local blaze = require "blaze"
local game = require "club.threecard.hbsl"

local Room = require "entities.Room"

local M = game.kbe.entity("HBSLRoom", Room)

function M:__init()
    Room.__init(self)
end

local phase2name = 
{
    [0] = "空闲",
    [1] = "抢红包",
    [2] = "结果展示",
    [3] = "结算",
}

function M:on_phase(phase_id, countdown)
    self.log.debug(string.format("当前阶段：%s 倒计时：%s", phase2name[phase_id], countdown))
    game.store.gameplay.set_phase({phase_id = phase_id, countdown = countdown})
end

function M:on_red_packet_appeared(sender_id, amount, size, no)
    self.log.debug(string.format("on_red_packet_appeared sender_id:%s, amount:%s, size:%s, no:%s", sender_id, amount, size, no))
    game.store.gameplay.on_red_packet_appeared({sender_id  = sender_id, amount = amount, size = size, no = no})
end

-- @view: {sender_id:发送者, n:雷号, win:庄家输赢, hits:{中雷记录id}, records:{{[1]=player_id, [2] = amount}}}
function M:on_reveal(view)
    self.log.debug(string.format("on_reveal: %s", blaze.dump(view)))
    game.store.self_record.on_reveal(view)
    game.store.gameplay.on_reveal(view)
end

-- @view{{player_id, payout}}
function M:on_settle(view)
    self.log.debug(string.format("结算： %s", blaze.dump(view)))
    game.store.gameplay.on_settle(view)
end

return M
